<?php
// +----------------------------------------------------------------------
// | 07FLYCRM [基于ThinkPHP5.0开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2021 http://www.07fly.xyz
// +----------------------------------------------------------------------
// | Professional because of focus  Persevering because of happiness
// +----------------------------------------------------------------------
// | Author: 开发人生 <goodkfrs@qq.com>
// +----------------------------------------------------------------------

namespace app\ten\controller;

use think\db;

/**
 * 用户控制器
 */
class TenTenant extends TenBase
{
    public function __construct()
    {
        parent::__construct();

        // 租户类型
        $tenant_type_list = $this->logicTenTenantType->getTenTenantTypeList([], '', '', false);
        $this->assign('tenant_type_list', $tenant_type_list);
    }

    /**
     * 菜单列表
     */
    public function show()
    {
        return $this->fetch('show');
    }

    public function show_json()
    {
        $where = $this->logicTenTenant->getWhere($this->param);
        $list = $this->logicTenTenant->getTenTenantList($where);
        return $list;
    }

    /**
     * 菜单添加
     */
    public function add()
    {
        IS_POST && $this->jump($this->logicTenTenant->tenTenantAdd($this->param));
        return $this->fetch('add');
    }

    /**
     * 系统用户编辑
     */
    public function edit()
    {
        IS_POST && $this->jump($this->logicTenTenant->tenTenantEdit($this->param));
        $info = $this->logicTenTenant->getTenTenantInfo(['id' => $this->param['id']]);
        $this->assign('info', $info);
        return $this->fetch('edit');
    }

    /**
     * 数据状态设置
     */
    public function del()
    {
        $where = empty($this->param['id']) ? ['id' => 0] : ['id' => $this->param['id']];
        $this->jump($this->logicTenTenant->tenTenantDel($where));
    }

    /**
     * 会员授权
     */
    public function createUser()
    {
        IS_POST && $this->jump($this->logicTenTenant->create_user($this->param));
        $info = $this->logicTenTenant->getTenTenantInfo(['id' => $this->param['id']]);
        $this->assign('info', $info);
        return $this->fetch('create_user');
    }

    public function detail()
    {
        IS_POST && $this->jump($this->logicTenTenant->tenUserEdit($this->param));
        $info = $this->logicTenTenant->getTenTenantInfo(['id' => $this->param['id']]);
        $this->assign('info', $info);
        return $this->fetch('detail');
    }

    /**
     * 启用
     */
    public function set_visible()
    {
        $this->jump($this->logicTenBase->setField('TenTenant', $this->param));
    }
}